from flask import Flask
from config import DevConfig
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
from werkzeug.utils import import_string


mail = Mail()
db = SQLAlchemy()
blueprints = [
    'flaskdemo.main:main',
    'flaskdemo.admin:admin',
]

def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    #load extensions
    mail.init_app(app)
    db.init_app(app)

    #load blueprints
    for bpname in blueprints:
        bp = import_string(bpname)
        app.register_blueprint(bp)

    return app







